package com.zz.parkingsystem.controller.inspector;

import com.zz.parkingsystem.entity.Inspector;
import com.zz.parkingsystem.entity.Order;
import com.zz.parkingsystem.entity.OrderItem;
import com.zz.parkingsystem.entity.Section;
import com.zz.parkingsystem.service.OrderItemService;
import com.zz.parkingsystem.service.OrderService;
import com.zz.parkingsystem.service.SectionService;
import com.zz.parkingsystem.util.Result;
import com.zz.parkingsystem.util.ResultGenerator;
import com.zz.parkingsystem.vo.AllOrderitemBySectionVo;
import com.zz.parkingsystem.vo.SectionAndParkingVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 已测selSectionOne方法
 已测selAllSection    ？？？？？？时间where条件有问题
 已测selOneOrderItem
 */
@RestController
@RequestMapping("ins/sections")
public class InsSectionController {
    @Resource
    private SectionService sectionService;
    @Resource
    private OrderItemService orderItemService;
    @Resource
    private OrderService orderService;
    @RequestMapping("/selSectionOne")//查一个街区的车位情况
    public Result  selSectionOne(){                     //secname从外面传进来，手动模拟"凤城7路"
        //查这个街区有多少空闲车位(返回给前端)
        int i1 = sectionService.getselectByPrimarybySecname("凤城7路");
        System.out.println("查这个街区有多少空闲车位"+i1);
        //查这个街区有多少车位已录入(返回给前端)
        int i2 = sectionService.getselectByPrimarybyBusy("凤城7路");
        System.out.println("查这个街区有多已录入车位"+i2);
        //查这个街区未录入的车位数量(返回给前端)
        int i3 = sectionService.getselectByPrimarybyNotBusy("凤城7路");
        System.out.println("查这个街区有多少未录入车位"+i3);
        //查所有的街区名称，封装集合(返回给前端)
        List<Section> list1 = sectionService.getselAllSection();  //list1.secName
        System.out.println("查所有的街区名称"+list1);
        //把空闲的泊位显示字段(泊位号，车位状态)返回前端
        //集合包含(泊位对应空闲车位集合)
        List list2 = sectionService.getselectByPrimarybySecnameShow("凤城7路");
        System.out.println("泊位对应空闲车位集合"+list2);
        //把录入车的泊位显示字段(泊位号，车牌号)返回前端
        //集合包含(泊位号，泊位对应已车牌号)
        List list3 = sectionService.getselectByPrimarybyBusyShow("凤城7路");
        System.out.println("泊位号，泊位对应已车牌号"+list3);
        //把未录入车的泊位显示字段(泊位号，车位状态)返回前端
        //集合包含(泊位号，泊位对应未录入车的状态)
        List<SectionAndParkingVo> list4 = sectionService.getselectByPrimarybyNotBusyShow("凤城7路");
        System.out.println("泊位号，泊位对应未录入车的状态"+list4);
        HashMap<String, Object> map = new HashMap<>();
        map.put("i1",i1);
        map.put("i2",i2);
        map.put("i3",i3);
        map.put("list1",list1);
        map.put("list2",list2);
        map.put("list3",list3);
        map.put("list4",list4);
        return ResultGenerator.genSuccessResult(map);
    }
    //巡检按照当日时间查所有订车订单和订车相关信息,页面传进来下拉框状态
    @RequestMapping("/selAllSection")
    @ApiOperation(value = "巡检查询",notes = "巡检按照当日时间查所有订车订单和订车相关信息")
    public Result selAllSection(@RequestParam(value = "order_status",required = false) Integer order_status ){   //传进来下拉框的选中的状态
        //查所有订单状态(下拉框列)
        List<Order> orders = orderService.getselectByAllStatus();
        System.out.println("下拉框列=================================="+orders);
//        Date date = new Date(); // ？？？？？？？？？？？？？？？？？？？？？？？？？？？
//        //============================时间转换===================================
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yy-MM-dd");
//        String dateStr = simpleDateFormat.format(date);
//        //============================时间转换====================================
       //该集合封装了订单号，泊位编号，车牌号，路段名称，驶入时间，停车时长，停车金额，
        // 停车状态(进行中，已缴费，未缴费)
        List<AllOrderitemBySectionVo> list2 = orderItemService.getselAllBySection(order_status);
        HashMap<String, Object> map = new HashMap<>();
        map.put("orders",orders);
        map.put("list2",list2);
        return ResultGenerator.genSuccessResult(map);
    }
    @PostMapping("/selOneOrderItem/{oi_no}")
    @ApiOperation(value = "巡检查询",notes = "巡检查询一个订单以及相关信息")
    public Result selOneOrderItem(@PathVariable("oi_no") String oi_no, HttpSession session){  //前端从上面方法取到订单流水号，传进来
        AllOrderitemBySectionVo SectionVo = orderItemService.getselOneOrderItem(oi_no);
        System.out.println(SectionVo+"3333333333333333333333333333333333333333333333333=====================================");
        //Inspector inspector = ( Inspector)session.getAttribute("inspector");
        //图片路径
       // OrderItem orderItem = orderItemService.getselImg(oi_no);
       // System.out.println(orderItem.getOiImgone()+"4444444444444444444444444444444444444444=====================================");
        HashMap<String, Object> map = new HashMap<>();
        map.put("SectionVo",SectionVo);//订单详情显示的其他信息(巡检，驶入图片单独sql)
       // map.put("inspector",inspector); //订单详情显示的巡检员
       // map.put("src",orderItem.getOiImgone()); //订单详情显示的巡检员
        return ResultGenerator.genSuccessResult(map);
    }
}
